home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 59.0 KB | 1,873 lines | [TEXT/MPS ] |
- //----------------------------------------------------------------------------------------
- // UMailable.cp
- // Copyright © 1984-96 by Apple Computer, Inc. All rights reserved.
- //----------------------------------------------------------------------------------------
-
- #if qPowerTalk
-
- #ifndef __UMAILABLE__
- #include "UMailable.h"
- #endif
-
- // MacApp
-
- #ifndef __UAPPLEEVENTS__
- #include "UAppleEvents.h"
- #endif
-
- #ifndef __UAPPLICATION__
- #include "UApplication.h"
- #endif
-
- #ifndef __UDISPATCHER__
- #include "UDispatcher.h"
- #endif
-
- #ifndef __UDOCUMENT__
- #include "UDocument.h"
- #endif
-
- #ifndef __UERRORMGR__
- #include "UErrorMgr.h"
- #endif
-
- #ifndef __UFILE__
- #include "UFile.h"
- #endif
-
- #ifndef __UMACAPPGLOBALS__
- #include "UMacAppGlobals.h"
- #endif
-
- #ifndef __UMACAPPUTILITIES__
- #include "UMacAppUtilities.h"
- #endif
-
- #ifndef __UMAILER__
- #include "UMailer.h"
- #endif
-
- #ifndef __UMAILERVIEW__
- #include "UMailerView.h"
- #endif
-
- #ifndef __UMEMORY__
- #include "UMemory.h"
- #endif
-
- #ifndef __UMENUMGR__
- #include "UMenuMgr.h"
- #endif
-
- #ifndef __UOBJECT__
- #include "UObject.h"
- #endif
-
- #ifndef __USCRIPTING__
- #include "UScripting.h"
- #endif
-
- #ifndef __UWINDOW__
- #include "UWindow.h"
- #endif
-
- // Toolbox
-
- #ifndef __AEREGISTRY__
- #include <AERegistry.h>
- #endif
-
- #if qPowerPC || qModelCFM
- #ifndef __FRAGLOAD__
- #include <FragLoad.h>
- #endif
- #endif
-
- #ifndef __OCESTANDARDDIRECTORY__
- #include <OCEStandardDirectory.h>
- #endif
-
- #ifndef __OCEERRORS__
- #include <OCEErrors.h>
- #endif
-
- // ANSI
-
- #ifndef __STDIO__
- #include <stdio.h>
- #endif
-
- //========================================================================================
- // GLOBAL Variables
- //========================================================================================
-
- MMailing* gMailing;
-
- //========================================================================================
- // CLASS CDirExtTypeTableIterator
- //========================================================================================
-
- #if PRAGMA_ALIGN_SUPPORTED
- #pragma options align=mac68k
- #endif
-
- struct DirExtTypeEntry
- {
- OSType extType;
- Boolean isRString;
- char fill1;
- char fill2;
- char fill3;
- CStr255 dirSysName;
- };
-
- struct DirExtTypeTable
- {
- short count;
- DirExtTypeEntry dirExtTypeDesc;
- };
-
- #if PRAGMA_ALIGN_SUPPORTED
- #pragma options align=reset
- #endif
-
- class CDirExtTypeTableIterator
- {
- long fCurrentIndex;
- long fNumOfExtTypes;
- DirExtTypeTable** fDirExtTypeTable;
- long fCurrentOffset; // offset to the current rstring in the resource.
-
- public:
- CDirExtTypeTableIterator(short resID);
-
- DirExtTypeEntry* FirstDirExtType();
- Boolean More();
- DirExtTypeEntry* NextDirExtType();
- };
-
- inline Boolean CDirExtTypeTableIterator::More(){ return fCurrentIndex <= fNumOfExtTypes; };
-
- //--------------------------------------------------------------------------------------------------
- // CDirExtTypeTableIterator::CDirExtTypeTableIterator
- //--------------------------------------------------------------------------------------------------
-
- CDirExtTypeTableIterator::CDirExtTypeTableIterator(short resID)
- {
- fCurrentIndex = 0;
- fNumOfExtTypes = 0;
- fCurrentOffset = 0;
-
- fDirExtTypeTable = (DirExtTypeTable**)MAGet1Resource('dxtt', resID);
- FailNILResource((Handle)fDirExtTypeTable);
-
- MoveHHi((Handle)fDirExtTypeTable);
- HLock((Handle)fDirExtTypeTable); // we assume its locked down.
-
- if (fDirExtTypeTable == 0)
- return;
-
- fNumOfExtTypes = (*fDirExtTypeTable)->count;
- }
-
- //--------------------------------------------------------------------------------------------------
- // CDirExtTypeTableIterator::FirstDirExtType
- //--------------------------------------------------------------------------------------------------
-
- DirExtTypeEntry* CDirExtTypeTableIterator::FirstDirExtType()
- {
- fCurrentIndex = 1;
- fCurrentOffset = 0;
- if (More())
- return (DirExtTypeEntry *)(((char*) & (*fDirExtTypeTable)->dirExtTypeDesc) + fCurrentOffset);
-
- return 0;
- }
-
- //--------------------------------------------------------------------------------------------------
- // CDirExtTypeTableIterator::NextDirExtType
- //--------------------------------------------------------------------------------------------------
-
- DirExtTypeEntry* CDirExtTypeTableIterator::NextDirExtType()
- {
- fCurrentIndex++;
- if (More())
- {
- DirExtTypeEntry* dirExtType = (DirExtTypeEntry*)(((char*) & (*fDirExtTypeTable)->dirExtTypeDesc) + fCurrentOffset);
-
- fCurrentOffset += sizeof(OSType) + 4 + dirExtType->dirSysName[0] + 1; // the size of each entry
-
- fCurrentOffset += (fCurrentOffset & 1); // align it.
-
- return (DirExtTypeEntry *)(((char*) & (*fDirExtTypeTable)->dirExtTypeDesc) + fCurrentOffset);
- }
-
- return 0;
- }
-
- //========================================================================================
- // CLASS CCatalogs
- //========================================================================================
-
- //--------------------------------------------------------------------------------------------------
- // CCatalogs::CCatalogs
- //--------------------------------------------------------------------------------------------------
-
- CCatalogs::CCatalogs()
- : fForEachDirectoryProc(NULL),
- fClientData(0),
- fDirectoryNameToFind(NULL),
- fCatalogFound(FALSE)
- {
- fStartingDirDiscriminator.signature = 0;
- fStartingDirDiscriminator.misc = 0;
- fFoundDirDiscriminator.signature = 0;
- fFoundDirDiscriminator.misc = 0;
- }
-
- //--------------------------------------------------------------------------------------------------
- // CCatalogs::EachDirectoryGlue
- //--------------------------------------------------------------------------------------------------
-
- Boolean CCatalogs::EachCatalogGlue(long clientData,
- const DirectoryName* dirName,
- const DirDiscriminator* discriminator,
- DirGestalt features)
- {
- Boolean done = TRUE;
- CCatalogs * theCatalogs = (CCatalogs *)clientData;
- ForEachDirectory myForEachDirectoryProc = theCatalogs->fForEachDirectoryProc;
- if (myForEachDirectoryProc)
- {
- FailInfo fi;
- Try(fi)
- {
- done = CallForEachDirectoryProc(myForEachDirectoryProc, clientData, dirName, discriminator, features);
- fi.Success();
- }
- else
- done = TRUE;
- }
- OCECopyRString((RStringPtr)dirName, (RStringPtr)&theCatalogs->fStartingDirectoryName, kRStringMaxBytes);
- theCatalogs->fStartingDirDiscriminator = *discriminator;
- return done;
- }
-
- //--------------------------------------------------------------------------------------------------
- // CCatalogs::EnumerateCatalogs
- //--------------------------------------------------------------------------------------------------
-
- void CCatalogs::EnumerateCatalogs(OCEDirectoryKind catalogType,
- ForEachDirectory actionProc)
- {
- const long kGetBufferSize = 1024;
-
- Boolean result = FALSE;
- OSErr getErr = kOCEMoreData;
- OSErr parseErr = kOCEMoreData;
- DirEnumerateDirectoriesGetPB getPB;
- DirEnumerateDirectoriesParsePB parsePB;
- ForEachDirectory eachCatalogProc = NULL;
-
- fForEachDirectoryProc = actionProc;
- getPB.getBuffer = NULL;
-
- FailInfo fi;
- Try(fi)
- {
- BlockSet((Ptr)&fStartingDirectoryName, sizeof(DirectoryName), 0);
- eachCatalogProc = NewForEachDirectoryProc(EachCatalogGlue);
- FailNIL(eachCatalogProc);
-
- getPB.ioCompletion = NULL;
- getPB.clientData = (long)this;
- getPB.directoryKind = catalogType;
- getPB.getBuffer = NewPermPtr(kGetBufferSize); // allocate the buffer
- FailNIL(getPB.getBuffer);
- getPB.getBufferSize = kGetBufferSize;
-
- parsePB.ioCompletion = NULL;
- parsePB.clientData = (long)this;
- parsePB.eachDirectory = eachCatalogProc;
- parsePB.getBuffer = getPB.getBuffer;
- parsePB.getBufferSize = kGetBufferSize;
-
- while ((getErr == kOCEMoreData) || (parseErr == kOCEMoreData))
- {
- getErr = DirEnumerateDirectoriesGet((DirParamBlockPtr)&getPB, FALSE);
- parseErr = DirEnumerateDirectoriesParse((DirParamBlockPtr)&parsePB, FALSE);
- getPB.includeStartingPoint = FALSE;
- getPB.startingDirectoryName = &fStartingDirectoryName;
- getPB.startingDirDiscriminator = fStartingDirDiscriminator;
- }
-
- getPB.getBuffer = DisposeIfPtr(getPB.getBuffer);
- eachCatalogProc = DisposeIfRoutineDescriptor(eachCatalogProc);
- FailOSErr(getErr);
- FailOSErr(parseErr);
- fi.Success();
- }
- else // Recover
- {
- getPB.getBuffer = DisposeIfPtr(getPB.getBuffer);
- eachCatalogProc = DisposeIfRoutineDescriptor(eachCatalogProc);
- fi.ReSignal();
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- // CCatalogs::FindCatalogByNameProc
- //--------------------------------------------------------------------------------------------------
-
- Boolean CCatalogs::FindCatalogByNameProc(long clientData,
- const DirectoryName* dirName,
- const DirDiscriminator* discriminator,
- DirGestalt/*features*/ )
- {
- CCatalogs * theCatalogs = (CCatalogs *)clientData;
- if (OCEEqualRString(dirName, theCatalogs->fDirectoryNameToFind, kOCEDirName))
- {
- theCatalogs->fFoundDirDiscriminator = *discriminator;
- theCatalogs->fCatalogFound = TRUE;
- }
- return theCatalogs->fCatalogFound;
- }
-
- //--------------------------------------------------------------------------------------------------
- // CCatalogs::FindCatalogByName
- //--------------------------------------------------------------------------------------------------
-
- Boolean CCatalogs::FindCatalogByName(DirectoryNamePtr theCatalogName,
- OCEDirectoryKind catalogType,
- DirDiscriminator& discriminator)
- {
- Boolean foundIt = FALSE;
- fCatalogFound = FALSE;
- fDirectoryNameToFind = theCatalogName;
- ForEachDirectory findCatalogProc = NewForEachDirectoryProc(FindCatalogByNameProc);
- FailInfo fi;
- Try(fi)
- {
- this->EnumerateCatalogs(catalogType, findCatalogProc);
- foundIt = fCatalogFound;
- if (foundIt)
- discriminator = fFoundDirDiscriminator;
- fi.Success();
- }
- else
- foundIt = FALSE;
- DisposeRoutineDescriptor((UniversalProcPtr)findCatalogProc);
- return foundIt;
- }
-
- //========================================================================================
- // CLASS CDSSpec
- //========================================================================================
-
- //--------------------------------------------------------------------------------------------------
- // CDSSpec::CDSSpec
- //--------------------------------------------------------------------------------------------------
-
- CDSSpec::CDSSpec()
- {
- fPackedDSSpec = NULL;
- fUnpacked = FALSE;
- }
-
- //--------------------------------------------------------------------------------------------------
- // CDSSpec::CDSSpec(PackedDSSpecPtr* aPackedDSSpec)
- //--------------------------------------------------------------------------------------------------
-
- CDSSpec::CDSSpec(PackedDSSpecPtr aPackedDSSpec)
- {
- long theSize = sizeof(ProtoPackedDSSpec) + aPackedDSSpec->dataLength;
- fPackedDSSpec = (PackedDSSpecPtr)NewPtr(theSize);
- MABlockMove((Ptr)aPackedDSSpec, (Ptr)fPackedDSSpec, theSize);
- this->Unpack();
- }
-
- //--------------------------------------------------------------------------------------------------
- // CDSSpec::CDSSpec(const CAEDesc& anAEDesc)
- //--------------------------------------------------------------------------------------------------
-
- CDSSpec::CDSSpec(const CAEDesc& anAEDesc)
- {
- long theSize = anAEDesc.GetDataSize();
- fPackedDSSpec = (PackedDSSpecPtr)NewPtr(theSize);
- MABlockMove(*anAEDesc.GetDataHandle(), (Ptr)fPackedDSSpec, theSize);
- this->Unpack();
- }
-
- //--------------------------------------------------------------------------------------------------
- // CDSSpec::~CDSSpec
- //--------------------------------------------------------------------------------------------------
-
- CDSSpec::~CDSSpec()
- {
- fPackedDSSpec = (PackedDSSpecPtr)DisposeIfPtr((Ptr)fPackedDSSpec);
- }
-
- //--------------------------------------------------------------------------------------------------
- // CDSSpec::Unpack
- //--------------------------------------------------------------------------------------------------
-
- Boolean CDSSpec::Unpack()
- {
- if (fPackedDSSpec)
- {
- unsigned short nodeCount = 0;
- if (OCEValidPackedDSSpec(fPackedDSSpec))
- {
- OCEUnpackDSSpec(fPackedDSSpec, &fDSSpec, &fRecordID);
- if (OCEValidPackedRLI(fRecordID.rli))
- {
- OCEUnpackRLI(fRecordID.rli, &fRLI);
- fUnpacked = TRUE;
- }
- }
- }
- return fUnpacked;
- }
-
- //--------------------------------------------------------------------------------------------------
- // CDSSpec::Pack
- //--------------------------------------------------------------------------------------------------
-
- void CDSSpec::Pack()
- {
- long theSize = OCEPackedRLISize(&fRLI);
- PackedRLIPtr thePackedRLI = (PackedRLIPtr)NewPtr(theSize);
- OCEPackRLI(&fRLI, thePackedRLI, theSize);
- fRecordID.rli = thePackedRLI;
- theSize = OCEPackedDSSpecSize(&fDSSpec);
- fPackedDSSpec = (PackedDSSpecPtr)DisposeIfPtr((Ptr)fPackedDSSpec);
- fPackedDSSpec = (PackedDSSpecPtr)NewPtr(theSize);
- FailOSErr(OCEPackDSSpec(&fDSSpec, fPackedDSSpec, theSize));
- DisposeIfPtr((Ptr)thePackedRLI);
- }
-
- //--------------------------------------------------------------------------------------------------
- // CDSSpec::GetExtensionType
- //--------------------------------------------------------------------------------------------------
-
- OSType CDSSpec::GetExtensionType()
- {
- if (fUnpacked)
- return this->fDSSpec.extensionType;
- else if (fPackedDSSpec)
- return OCEGetExtensionType(fPackedDSSpec);
- else
- return '\?\?\?\?';
- }
-
- //--------------------------------------------------------------------------------------------------
- // CDSSpec::GetExtensionValue
- //--------------------------------------------------------------------------------------------------
-
- void CDSSpec::GetPathName(CStr255& thePathName)
- {
- DirParamBlockPtr pb = (DirParamBlockPtr)NewPtrClear(sizeof(DirParamBlock));
- PackedPathNamePtr packedPathName = (PackedPathNamePtr)NewPtrClear(kPathNameMaxBytes);
- gMailing->GetAOCEIdentity(pb->mapDNodeNumberToPathNamePB.identity, FALSE);
- pb->mapDNodeNumberToPathNamePB.directoryName = this->fRLI.directoryName;
- pb->mapDNodeNumberToPathNamePB.discriminator = this->fRLI.discriminator;
- pb->mapDNodeNumberToPathNamePB.dNodeNumber = this->fRLI.dNodeNumber;
- pb->mapDNodeNumberToPathNamePB.path = packedPathName;
- pb->mapDNodeNumberToPathNamePB.lengthOfPathName = kPathNameMaxBytes;
- OSErr anErr = DirMapDNodeNumberToPathName(pb, FALSE);
- if (anErr == noErr)
- {
- thePathName = this->GetDirectoryName();
- RStringPtr parts[16];
- unsigned short numParts = OCEUnpackPathName(packedPathName, parts, 16);
- while (numParts)
- {
- CStr255 pathPart = OCERToPString(parts[--numParts]);
- thePathName += ':';
- thePathName += pathPart;
- }
- }
- DisposeIfPtr((Ptr)pb);
- DisposeIfPtr((Ptr)packedPathName);
- }
-
- //--------------------------------------------------------------------------------------------------
- // CDSSpec::GetAEDesc(CAEDesc& theAEDesc)
- //--------------------------------------------------------------------------------------------------
-
- void CDSSpec::GetAEDesc(CAEDesc& theAEDesc)
- {
- if (fPackedDSSpec)
- {
- theAEDesc.CreateDesc(typePackedDSSpec, (Ptr)fPackedDSSpec, sizeof(ProtoPackedDSSpec) + fPackedDSSpec->dataLength);
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- // CDSSpec::UnpackDirectDialupInfo
- //--------------------------------------------------------------------------------------------------
-
- PhoneNumberInfo* CDSSpec::UnpackDirectDialupInfo()
- {
- if (!fUnpacked)
- return NULL;
- PhoneNumberInfo * phoneInfo = (PhoneNumberInfo *)NewPtr(sizeof(PhoneNumberInfo));
- Ptr ext = (Ptr)(fDSSpec.extensionValue + sizeof(ProtoRString));
- phoneInfo->fSubType = *(short*)ext;
- ext += sizeof(short);
- phoneInfo->fCountryCode = UnpackRString(ext);
- phoneInfo->fAreaCode = UnpackRString(ext);
- phoneInfo->fPhoneNumber = UnpackRString(ext);
- phoneInfo->fPostFix = UnpackRString(ext);
- phoneInfo->fDirectDial = UnpackRString(ext);
- return phoneInfo;
- }
-
- //--------------------------------------------------------------------------------------------------
- // CDSSpec::UnpackSTFFaxInfo
- //--------------------------------------------------------------------------------------------------
-
- PhoneNumberInfo* CDSSpec::UnpackSTFFaxInfo()
- {
- if (!fUnpacked)
- return NULL;
- PhoneNumberInfo * phoneInfo = (PhoneNumberInfo *)NewPtr(sizeof(PhoneNumberInfo));
- Ptr ext = (Ptr)(fDSSpec.extensionValue);
- phoneInfo->fDirectDial = UnpackRString(ext);
- phoneInfo->fCountryCode = UnpackRString(ext);
- phoneInfo->fAreaCode = UnpackRString(ext);
- phoneInfo->fPhoneNumber = UnpackRString(ext);
- phoneInfo->fPostFix = UnpackRString(ext);
- phoneInfo->fSubType = (short) * (long*)ext;
- return phoneInfo;
- }
-
- //--------------------------------------------------------------------------------------------------
- // CDSSpec::PackString
- //--------------------------------------------------------------------------------------------------
-
- void CDSSpec::PackString(Ptr& packIn,
- const CStr31& theStr)
- {
- long theSize = theStr.Length() + 1;
- MABlockMove(&theStr, packIn, theSize);
- if (theSize % 2) // odd number string, add the padding
- theSize++;
- packIn += theSize;
- }
-
- //--------------------------------------------------------------------------------------------------
- // CDSSpec::PackRString
- //--------------------------------------------------------------------------------------------------
-
- void CDSSpec::PackRString(Ptr& packIn,
- const CStr31& theStr)
- {
- RString theRStr;
- OCEPToRString(theStr, smRoman, &theRStr, kRStringMaxBytes);
- long theSize = theRStr.dataLength + sizeof(ProtoRString);
- MABlockMove(&theRStr, packIn, theSize);
- if (theSize % 2) // odd number string, add the padding
- theSize++;
- packIn += theSize;
- }
-
- //--------------------------------------------------------------------------------------------------
- // CDSSpec::PackRString
- //--------------------------------------------------------------------------------------------------
-
- void CDSSpec::PackRString(Ptr& packIn,
- RStringPtr theStr)
- {
- long theSize = theStr->dataLength + sizeof(ProtoRString);
- MABlockMove(theStr, packIn, theSize);
- if (theSize % 2) // odd number string, add the padding
- theSize++;
- packIn += theSize;
- }
-
- //--------------------------------------------------------------------------------------------------
- // CDSSpec::UnpackRString
- //--------------------------------------------------------------------------------------------------
-
- StringPtr CDSSpec::UnpackRString(Ptr& unpackFrom)
- {
- StringPtr result = OCERToPString((RStringPtr)unpackFrom);
- unpackFrom = unpackFrom + ((RStringPtr)unpackFrom)->dataLength + sizeof(ProtoRString);
- if (result[0] % 2) // odd number string, skip the padding
- unpackFrom++;
- return result;
- }
-
- //--------------------------------------------------------------------------------------------------
- // CDSSpec::GetDirectoryExtensionType
- //--------------------------------------------------------------------------------------------------
-
- Boolean CDSSpec::GetDirectoryExtensionType(OSType myExtType, Boolean& isRString, CStr255& dirSysName)
- {
- Boolean found = FALSE;
-
- DirExtTypeEntry* defaultDirExtType;
-
- CDirExtTypeTableIterator iter(kDirExtTypeTableID);
- for (DirExtTypeEntry* dirExtType = iter.FirstDirExtType(); iter.More(); dirExtType = iter.NextDirExtType())
- {
- defaultDirExtType = dirExtType;
- if (myExtType == dirExtType->extType)
- {
- found = TRUE;
- isRString = dirExtType->isRString;
- dirSysName = CStr255(dirExtType->dirSysName);
- break;
- }
- }
-
- if (!found)
- {
- isRString = defaultDirExtType->isRString;
- dirSysName = CStr255(defaultDirExtType->dirSysName);
- }
-
- return found;
- }
-
- //--------------------------------------------------------------------------------------------------
- // CDSSpec::AddressToString
- //--------------------------------------------------------------------------------------------------
-
- void CDSSpec::AddressToString(CStr255& theString)
- {
- OSType myExtType = this->GetExtensionType();
- CStr255 recName(GetRecordName());
-
- Boolean isRString;
- CStr255 dirSysName;
-
- Boolean found = GetDirectoryExtensionType(myExtType, isRString, dirSysName);
- if (found)
- {
- if (isRString)
- {
- CStr255 dirName(GetDirectoryName());
- if (dirName.Length())
- {
- dirName = "<" + dirName + '>';
- if (dirName == dirSysName)
- dirName.Empty(); // don't include redundant directory names
- }
- theString = recName + dirSysName + dirName + CStr255(OCERToPString((RString *)fDSSpec.extensionValue));
- }
- else
- {
- switch (myExtType)
- {
- // PowerShare
- case kOCEentnXtn:
- {
- CStr255 pathName;
- GetPathName(pathName);
- theString = recName + dirSysName + pathName;
- break;
- }
-
- // AppleTalk
- case kOCEalanXtn:
- {
- Ptr ext = (Ptr)fDSSpec.extensionValue;
- CStr31 name((StringPtr)fDSSpec.extensionValue);
- CStr31 zone((StringPtr)(&ext[0] + ext[0] + 1 + ext[ext[0] + 1] + 1));
- // length of 1st pstring + length byte + length of 2nd pstring + length byte
- theString.fStr[0] = sprintf((char*) & theString.fStr[1], "%s%s%s@%s",
- (const char*)recName, (const char*)dirSysName,
- (const char*)name, (const char*)zone);
- break;
- }
-
- // Direct Dialup
- case kOCEaphnXtn:
- {
- PhoneNumberInfo* phoneInfo = this->UnpackDirectDialupInfo();
- if (phoneInfo)
- {
- if (phoneInfo->fSubType == kOCEUseHandyDial)
- theString.fStr[0] = sprintf((char*) & theString.fStr[1], "%s%s%s(%s)%s",
- (const char*)recName, (const char*)dirSysName,
- (const char*)phoneInfo->fCountryCode,
- (const char*)phoneInfo->fAreaCode,
- (const char*)phoneInfo->fPhoneNumber);
- else if (phoneInfo->fSubType == kOCEDontUseHandyDial)
- theString.fStr[0] = sprintf((char*) & theString.fStr[1], "%s%s%s",
- (const char*)recName, (const char*)dirSysName,
- (const char*)phoneInfo->fDirectDial);
- DisposeIfPtr((Ptr)phoneInfo);
- }
- break;
- }
-
- // Fax
- case 'TFAX':
- {
- PhoneNumberInfo* phoneInfo = this->UnpackSTFFaxInfo();
- if (phoneInfo)
- {
- if (phoneInfo->fSubType == 1)
- theString.fStr[0] = sprintf((char*) & theString.fStr[1], "%s%s%s(%s)%s",
- (const char*)recName, (const char*)dirSysName,
- (const char*)phoneInfo->fCountryCode,
- (const char*)phoneInfo->fAreaCode,
- (const char*)phoneInfo->fPhoneNumber);
- else
- theString.fStr[0] = sprintf((char*) & theString.fStr[1], "%s%s%s",
- (const char*)recName, (const char*)dirSysName,
- (const char*)phoneInfo->fDirectDial);
- DisposeIfPtr((Ptr)phoneInfo);
- }
- break;
- }
-
- default:
- break;
- }
- }
- }
- else if (theString.Length() == 0)
- theString = recName + dirSysName;
- }
-
- //--------------------------------------------------------------------------------------------------
- // CDSSpec::ParseDirectDialupAddress
- //--------------------------------------------------------------------------------------------------
-
- void CDSSpec::ParseDirectDialupAddress(CStr255& dsExtValue)
- {
- MAVolatileInit(PhoneNumberInfo * , phoneInfo, NULL);
- MAVolatileInit(Ptr, phoneNumberStr, NULL);
- FailInfo fi;
- Try(fi)
- {
- phoneInfo = (PhoneNumberInfo *)NewPtrClear(sizeof(PhoneNumberInfo));
- phoneInfo->fSubType = kOCEDontUseHandyDial;
- // look for an area code
- unsigned char startChar = dsExtValue.Pos("(", 1);
- unsigned char endChar = 0;
- if (startChar)
- {
- endChar = dsExtValue.Pos(")", startChar) + 1;
- phoneInfo->fSubType = kOCEUseHandyDial;
- phoneInfo->fCountryCode = dsExtValue.Copy(1, startChar - 1);
- phoneInfo->fAreaCode = dsExtValue.Copy(startChar + 1, endChar - startChar - 2);
- phoneInfo->fPhoneNumber = dsExtValue.Copy(endChar, dsExtValue.Length());
- }
- else
- {
- phoneInfo->fDirectDial = dsExtValue;
- }
- phoneNumberStr = NewPtrClear(sizeof(PhoneNumberInfo) + sizeof(ProtoRString));
- Ptr ext = (Ptr)(phoneNumberStr + sizeof(ProtoRString));
- Ptr startExt = ext;
- *(short*)ext = phoneInfo->fSubType;
- ext += sizeof(short);
- PackRString(ext, phoneInfo->fCountryCode);
- PackRString(ext, phoneInfo->fAreaCode);
- PackRString(ext, phoneInfo->fPhoneNumber);
- PackRString(ext, phoneInfo->fPostFix);
- PackRString(ext, phoneInfo->fDirectDial);
- ((RStringPtr)phoneNumberStr)->charSet = smRoman;
- ((RStringPtr)phoneNumberStr)->dataLength = ext - startExt;
-
- fDSSpec.extensionValue = NewPtrClear((sizeof(RString) * 2) + sizeof(CStr31));
- ext = fDSSpec.extensionValue;
- startExt = ext;
- PackRString(ext, (RStringPtr)phoneNumberStr);
- PackRString(ext, gEmptyString); // reserved, modem string
- PackString(ext, "InMail_Queue"); // "InMail_Queue"
- fDSSpec.extensionSize = ext - startExt;
-
- DisposeIfPtr((Ptr)phoneInfo);
- DisposeIfPtr((Ptr)phoneNumberStr);
- fi.Success();
- }
- else
- {
- DisposeIfPtr((Ptr)phoneInfo);
- DisposeIfPtr((Ptr)phoneNumberStr);
- fi.ReSignal();
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- // CDSSpec::ParseAppleTalkAddress
- //--------------------------------------------------------------------------------------------------
-
- void CDSSpec::ParseAppleTalkAddress(CStr255& dsExtValue)
- {
- Ptr theEntity = NewPtrClear(sizeof(EntityName));
- // Parses the extension string into an AppleTalk EntityName.
- unsigned char startChar = dsExtValue.Pos("@", 1);
- CStr31 objStr;
- CStr31 zoneStr = "*";
- CStr31 typeStr = kIPMWSReceiverNBPType;
- if (startChar > 0)
- {
- objStr = dsExtValue.Copy(1, startChar - 1);
- zoneStr = dsExtValue.Copy(startChar + 1, dsExtValue.Length());
- }
- NBPSetEntity(theEntity, objStr, typeStr, zoneStr);
- fDSSpec.extensionValue = theEntity; // caller will toss the extension value pointer
- fDSSpec.extensionSize = objStr.Length() + typeStr.Length() + zoneStr.Length() + 3;
- // Get the record type from the 'rast' resource and stuff it in
- Handle rastHandle = MAGet1Resource('rast', kAppleTalkRecordType);
- FailNILResource(rastHandle);
- HLock(rastHandle);
- OCECopyRString((RStringPtr) * rastHandle, fRecordID.local.recordType, kRStringMaxBytes);
- ReleaseResource(rastHandle);
- // Setup the RLI
- fRLI.discriminator.signature = 'atlk';
- fRLI.discriminator.misc = kDirDSAMKind;
- fRLI.dNodeNumber = 0;
- }
-
- //--------------------------------------------------------------------------------------------------
- // CDSSpec::ParsePowerShareAddress
- //--------------------------------------------------------------------------------------------------
-
- void CDSSpec::ParsePowerShareAddress(CStr31& dsDirName,
- CStr255& dsExtValue)
- {
- // Parses a path name to a catalog record and sets the fRLI to point to it.
- MAVolatileInit(short, numParts, 1);
- MAVolatileInit(short, partIndex, 15);
- MAVolatileInit(DirParamBlockPtr, pb, NULL);
- MAVolatileInit(PackedPathNamePtr, thePackedPath, NULL);
- RStringPtr parts[16];
- BlockSet((Ptr)&parts[0], sizeof(parts), 0);
- FailInfo fi;
- Try(fi)
- {
- // Get the directory name from the start of the path
- dsDirName = dsExtValue;
- unsigned char startChar = dsExtValue.Pos(":", 1);
- if (startChar > 0)
- {
- dsDirName = dsExtValue.Copy(1, startChar - 1);
- dsExtValue.Delete(1, startChar);
- }
- OCEPToRString(dsDirName, smRoman, (RStringPtr)fRLI.directoryName, kRStringMaxBytes);
- // get the discriminator
- CCatalogs theCatalogs;
- theCatalogs.FindCatalogByName(fRLI.directoryName, kDirADAPKind, fRLI.discriminator);
- // create a packed path name
- startChar = dsExtValue.Pos(":", 1);
- while ((startChar > 0) && (partIndex > 0))
- {
- CStr31 pathPart = dsExtValue.Copy(1, startChar - 1);
- dsExtValue.Delete(1, startChar);
- startChar = dsExtValue.Pos(":", 1);
- parts[partIndex] = (RStringPtr)NewPtr(sizeof(RString));
- OCEPToRString(pathPart, smRoman, parts[partIndex], kRStringMaxBytes);
- partIndex--;
- numParts++;
- }
- parts[partIndex] = (RStringPtr)NewPtr(sizeof(RString));
- OCEPToRString(dsExtValue, smRoman, parts[partIndex], kRStringMaxBytes);
- MABlockMove(&parts[partIndex], &parts[0], numParts * sizeof(RStringPtr));
- unsigned short packedPathSize = OCEPackedPathNameSize(parts, numParts);
- thePackedPath = (PackedPathNamePtr)NewPtr(packedPathSize);
- FailOSErr(OCEPackPathName(parts, numParts, thePackedPath, packedPathSize));
-
- pb = (DirParamBlockPtr)NewPtrClear(sizeof(DirParamBlock));
- gMailing->GetAOCEIdentity(pb->mapPathNameToDNodeNumberPB.identity, FALSE);
- pb->mapPathNameToDNodeNumberPB.directoryName = fRLI.directoryName;
- pb->mapPathNameToDNodeNumberPB.discriminator = fRLI.discriminator;
- pb->mapPathNameToDNodeNumberPB.path = thePackedPath;
- FailOSErr(DirMapPathNameToDNodeNumber(pb, FALSE));
- fRLI.dNodeNumber = pb->mapPathNameToDNodeNumberPB.dNodeNumber;
- thePackedPath = (PackedPathNamePtr)DisposeIfPtr((Ptr)thePackedPath);
- for (short pi = 0; pi < numParts; pi++)
- parts[pi] = (RStringPtr)DisposeIfPtr((Ptr)parts[pi]);
- pb = (DirParamBlockPtr)DisposeIfPtr((Ptr)pb);
- fi.Success();
- }
- else
- {
- thePackedPath = (PackedPathNamePtr)DisposeIfPtr((Ptr)thePackedPath);
- for (short pi = 0; pi < numParts; pi++)
- parts[pi] = (RStringPtr)DisposeIfPtr((Ptr)parts[pi]);
- pb = (DirParamBlockPtr)DisposeIfPtr((Ptr)pb);
- fi.ReSignal();
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- // CDSSpec::ParseFaxSTFAddress
- //--------------------------------------------------------------------------------------------------
-
- void CDSSpec::ParseFaxSTFAddress(CStr31& dsRecName,
- CStr255& dsExtValue)
- {
- // Parses a phone number string into a format for the STF fax PMSAM.
- MAVolatileInit(PhoneNumberInfo * , phoneInfo, NULL);
- MAVolatileInit(Ptr, phoneNumberStr, NULL);
- FailInfo fi;
- Try(fi)
- {
- phoneInfo = (PhoneNumberInfo *)NewPtrClear(sizeof(PhoneNumberInfo));
- // look for an area code
- unsigned char startChar = dsExtValue.Pos("(", 1);
- unsigned char endChar = 0;
- long useSmartDialing = 0;
- if (startChar)
- {
- useSmartDialing = 1;
- endChar = dsExtValue.Pos(")", startChar) + 1;
- phoneInfo->fCountryCode = dsExtValue.Copy(1, startChar - 1);
- phoneInfo->fAreaCode = dsExtValue.Copy(startChar + 1, endChar - startChar - 2);
- phoneInfo->fPhoneNumber = dsExtValue.Copy(endChar, dsExtValue.Length());
- }
- else
- {
- phoneInfo->fDirectDial = dsExtValue;
- phoneInfo->fPhoneNumber = dsExtValue;
- }
- phoneNumberStr = NewPtrClear(sizeof(PhoneNumberInfo) + sizeof(ProtoRString));
- Ptr ext = (Ptr)(phoneNumberStr + sizeof(ProtoRString));
- Ptr startExt = ext;
- PackRString(ext, phoneInfo->fDirectDial);
- PackRString(ext, phoneInfo->fCountryCode);
- PackRString(ext, phoneInfo->fAreaCode);
- PackRString(ext, phoneInfo->fPhoneNumber);
- PackRString(ext, dsRecName);
- *(long*)ext = useSmartDialing;
- ext += sizeof(long);
- ((RStringPtr)phoneNumberStr)->charSet = smRoman;
- long theSize = ext - startExt;
- ((RStringPtr)phoneNumberStr)->dataLength = theSize;
- theSize += sizeof(ProtoRString);
- fDSSpec.extensionValue = phoneNumberStr;
- fDSSpec.extensionSize = theSize;
- phoneInfo = (PhoneNumberInfo *)DisposeIfPtr((Ptr)phoneInfo);
- fi.Success();
- }
- else
- {
- phoneInfo = (PhoneNumberInfo *)DisposeIfPtr((Ptr)phoneInfo);
- fi.ReSignal();
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- // CDSSpec::ParseRStringAddress
- //--------------------------------------------------------------------------------------------------
-
- void CDSSpec::ParseRStringAddress(CStr255& dsExtValue)
- {
- // The default MSAM address format is an RString in the extensionValue.
- fDSSpec.extensionValue = NewPtr(sizeof(RString));
- OCEPToRString(dsExtValue, smRoman, (RStringPtr)fDSSpec.extensionValue, kRStringMaxBytes);
- fDSSpec.extensionSize = sizeof(ProtoRString) + ((RStringPtr)fDSSpec.extensionValue)->dataLength;
- }
-
- //--------------------------------------------------------------------------------------------------
- // CDSSpec::StringToAddress
- //--------------------------------------------------------------------------------------------------
-
- void CDSSpec::StringToAddress(CStr255& theString)
- {
- MAVolatileInit(RStringPtr, recName, NULL);
- MAVolatileInit(RStringPtr, recType, NULL);
- MAVolatileInit(RStringPtr, dirName, NULL);
- fDSSpec.extensionValue = NULL;
- fUnpacked = FALSE;
- FailInfo fi;
- Try(fi)
- {
- unsigned short theSize = 0;
- PackedRLIPtr thePackedRLI = NULL;
- CStr255 str;
- recName = (RStringPtr)NewPtrClear(sizeof(RString));
- recType = (RStringPtr)NewPtrClear(sizeof(RString));
- dirName = (RStringPtr)NewPtrClear(sizeof(RString));
-
- fRLI.directoryName = (DirectoryNamePtr)dirName;
- fRLI.discriminator.signature = ' ';
- fRLI.discriminator.misc = 0;
- fRLI.dNodeNumber = 0;
- fRLI.path = NULL;
-
- fRecordID.local.recordName = recName;
- fRecordID.local.recordType = recType;
- fRecordID.local.cid = *OCENullCID();
- fRecordID.rli = NULL;
-
- fDSSpec.entitySpecifier = &fRecordID;
- fDSSpec.extensionType = '\?\?\?\?';
- fDSSpec.extensionSize = 0;
- fDSSpec.extensionValue = NULL;
-
- unsigned char startChar = theString.Pos("<", 1);
- unsigned char endChar = theString.Pos(">", startChar) + 1;
- CStr31 dsRecName = theString.Copy(1, startChar - 1);
- CStr255 dsDirType = theString.Copy(startChar, endChar - startChar);
- CStr255 dsExtValue = theString.Copy(endChar, theString.Length());
- CStr31 dsDirName;
- startChar = dsExtValue.Pos("<", 1);
- if (startChar)
- {
- // see if there is a directory name
- endChar = dsExtValue.Pos(">", startChar) + 1;
- dsDirName = dsExtValue.Copy(2, endChar - 3);
- dsExtValue = dsExtValue.Copy(endChar, dsExtValue.Length());
- }
-
- OCEPToRString(dsRecName, smRoman, fRecordID.local.recordName, kRStringMaxBytes);
-
- CDirExtTypeTableIterator iter(kDirExtTypeTableID);
- DirExtTypeEntry * defaultDirExtType = 0;
- for (DirExtTypeEntry * dirExtType = iter.FirstDirExtType(); iter.More(); dirExtType = iter.NextDirExtType())
- {
-
- defaultDirExtType = dirExtType;
-
- if (dsDirType == dirExtType->dirSysName)
- {
- fDSSpec.extensionType = dirExtType->extType;
- if (dsDirName.Length() == 0)
- {
- // get the default directory name
- dsDirName = dirExtType->dirSysName;
- // get rid of the <> around the name
- dsDirName.Delete(dsDirName.Length(), 1);
- dsDirName.Delete(1, 1);
- }
- OCECToRString(kUserRecTypeBody, smRoman, fRecordID.local.recordType, kRStringMaxBytes);
- OCEPToRString(dsDirName, smRoman, (RStringPtr)fRLI.directoryName, kRStringMaxBytes);
- fRLI.discriminator.signature = fDSSpec.extensionType;
- fRLI.discriminator.misc = 0;
- fRLI.dNodeNumber = 0;
-
- switch (fDSSpec.extensionType)
- {
- case kOCEentnXtn:
- this->ParsePowerShareAddress(dsDirName, dsExtValue);
- break;
-
- case kOCEalanXtn:
- this->ParseAppleTalkAddress(dsExtValue);
- break;
-
- case kOCEaphnXtn:
- this->ParseDirectDialupAddress(dsExtValue);
- break;
-
- case 'TFAX':
- this->ParseFaxSTFAddress(dsRecName, dsExtValue);
-
- default:
- this->ParseRStringAddress(dsExtValue);
- break;
- }
- break;
- }
- }
- this->Pack();
- recName = (RStringPtr)DisposeIfPtr((Ptr)recName);
- recType = (RStringPtr)DisposeIfPtr((Ptr)recType);
- dirName = (RStringPtr)DisposeIfPtr((Ptr)dirName);
- fDSSpec.extensionValue = DisposeIfPtr(fDSSpec.extensionValue);
- this->Unpack();
- fi.Success();
- }
- else
- {
- recName = (RStringPtr)DisposeIfPtr((Ptr)recName);
- recType = (RStringPtr)DisposeIfPtr((Ptr)recType);
- dirName = (RStringPtr)DisposeIfPtr((Ptr)dirName);
- fDSSpec.extensionValue = DisposeIfPtr(fDSSpec.extensionValue);
- fi.ReSignal();
- }
- }
-
- //========================================================================================
- // CLASS MMailable
- //========================================================================================
- #undef Inherited
-
- #pragma segment MAOpen
- MA_DEFINE_CLASS_M0(MMailable);
-
- //----------------------------------------------------------------------------------------
- // MMailable constructor
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- MMailable::MMailable()
- {
- fLetter = NULL;
- fMailCreator = gDispatcher->fCreator; // default letter creator
- fMailType = gMailing->fMainLetterFileType; // default letter type
- fSendFormats = kSMPNativeMask + kSMPImageMask + kSMPStandardInterchangeMask;
- }
-
- //----------------------------------------------------------------------------------------
- // MMailable::Free:
- //----------------------------------------------------------------------------------------
- #pragma segment MAClose
-
- MMailable::~MMailable()
- {
- fLetter = (TLetter*) FreeIfObject(fLetter);
- }
-
- //----------------------------------------------------------------------------------------
- // MMailable::AddNativeMailContent
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void MMailable::AddNativeMailContent(Boolean& okToSend)
- {
- FailNonObject(fLetter);
- fLetter->AddNativeMailContent(okToSend);
- }
-
- //----------------------------------------------------------------------------------------
- // MMailable::AddSnapshotMailContent
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void MMailable::AddSnapshotMailContent(Boolean& okToSend)
- {
- FailNonObject(fLetter);
- fLetter->AddSnapshotMailContent(okToSend);
- }
-
- //----------------------------------------------------------------------------------------
- // MMailable::AddStandardMailContent
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void MMailable::AddStandardMailContent(Boolean& okToSend)
- {
- FailNonObject(fLetter);
- fLetter->AddStandardMailContent(okToSend);
- }
-
- //----------------------------------------------------------------------------------------
- // MMailable::CountContainedMailers:
- //----------------------------------------------------------------------------------------
- #pragma segment OSLDispatchRes
-
- long MMailable::CountContainedMailers()
- {
- long count = 0;
-
- if (fLetter)
- count = fLetter->CountContainedMailers();
-
- return count;
- }
-
- //----------------------------------------------------------------------------------------
- // MMailable::DoAECreateMailer
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void MMailable::DoAECreateMailer(TAppleEvent* message,
- TAppleEvent* reply)
- {
- if (!fLetter)
- DoMakeLetter();
- FailNonObject(fLetter);
- fLetter->DoAECreateMailer(message, reply);
- }
-
- //----------------------------------------------------------------------------------------
- // MMailable::DoAECreateReply
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void MMailable::DoAECreateReply(TAppleEvent* message,
- TAppleEvent* reply)
- {
- if (!fLetter)
- DoMakeLetter();
- FailNonObject(fLetter);
- fLetter->DoAECreateReply(message, reply);
- }
-
- //----------------------------------------------------------------------------------------
- // MMailable::DoAESend
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void MMailable::DoAESend(TAppleEvent* message,
- TAppleEvent* reply)
- {
- FailNonObject(fLetter);
- fLetter->DoAESend(message, reply);
- }
-
- //----------------------------------------------------------------------------------------
- // MMailable::DoMailMenuCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- Boolean MMailable::DoMailMenuCommand(CommandNumber aCommandNumber)
- {
- Boolean handled = FALSE;
-
- if ((aCommandNumber == cAddMailer) && !fLetter)
- DoMakeLetter();
-
- if (fLetter)
- handled = fLetter->DoMailMenuCommand(aCommandNumber);
-
- return handled;
- }
-
- //----------------------------------------------------------------------------------------
- // MMailable::DoMakeLetter
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void MMailable::DoMakeLetter()
- {
- // The default implementation makes a TFileBasedLetter, which is intended
- // to work with a TFileBasedDocument. If your document is not a subclass of
- // TFileBasedDocument, override this method to make a TLetter subclass that
- // works with your document.
-
- if (!fLetter)
- {
- TFileBasedLetter* it = new TFileBasedLetter;
- it->IFileBasedLetter(this);
- fLetter = it;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // MMailable::DoSetupMailMenus:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentRes
-
- void MMailable::DoSetupMailMenus()
- {
- if (HasAOCEToolBox())
- {
- if (!fLetter)
- {
- SetIndividualCommandName(cAddMailer, kAOCEStrings, kAddMailerCmdName);
- Enable(cAddMailer, TRUE);
- }
- else
- fLetter->DoSetupMailMenus();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // MMailable::FindLetter
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- TDocument* MMailable::FindLetter(Handle /*itsSpec*/)
- {
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // MMailable::GetIndContainedMailer
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- MScriptableObject* MMailable::GetIndContainedMailer(long index)
- {
- MScriptableObject* mailer = NULL;
-
- if (fLetter)
- mailer = fLetter->GetIndContainedMailer(index);
-
- return mailer;
- }
-
- //----------------------------------------------------------------------------------------
- // MMailable::GetSendFormats
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- unsigned long MMailable::GetSendFormats()
- {
- return fSendFormats;
- }
-
- //----------------------------------------------------------------------------------------
- // MMailable::HasMailer
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- Boolean MMailable::HasMailer()
- {
- return (fLetter != NULL) ? fLetter->HasMailer() : NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // MMailable::ImageDocumentForLetter
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void MMailable::ImageDocumentForLetter(Boolean /*inColor*/)
- {
- // Override to draw your document contents.
- }
-
- //----------------------------------------------------------------------------------------
- // MMailable::LetterContentChanged
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void MMailable::LetterContentChanged()
- {
- if (fLetter)
- fLetter->LetterContentChanged();
- }
-
- //----------------------------------------------------------------------------------------
- // MMailable::MakeRoomForMailer
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void MMailable::MakeRoomForMailer(long amount, Boolean redraw)
- {
- // This implementation assumes your window's main content view
- // is a scroller with ID 'SCLR'. If your views are organized
- // differently, override this method to move your views around.
-
- if (fLetter)
- {
- TWindow* mailerWindow = fLetter->GetMailerWindow();
- FailNonObject(mailerWindow);
- TView* theView = mailerWindow->FindSubView('SCLR');
- FailNonObject(theView);
- VRect viewFrame(theView->GetFrame());
- viewFrame.top += amount;
- theView->SetFrame(viewFrame, kDontInvalidate);
-
- if (redraw && mailerWindow->Focus())
- {
- mailerWindow->ForceRedraw(); // invalidate window
-
- // validate mailer view to prevent flash
- TMailerView* theMailerView = fLetter->GetMailerView();
- if (theMailerView != NULL)
- {
- CTemporaryRegion visibleRgn;
- theMailerView->GetVisibleRegion(visibleRgn);
- theMailerView->ValidateRegion(visibleRgn);
- }
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // MMailable::OpenLetter
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void MMailable::OpenLetter()
- {
- fLetter->OpenLetter();
- }
-
- //----------------------------------------------------------------------------------------
- // MMailable::ReadLetter
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void MMailable::ReadLetter(Boolean forPrinting)
- {
- if (!fLetter)
- DoMakeLetter();
-
- fLetter->ReadLetter(forPrinting);
- }
-
- //----------------------------------------------------------------------------------------
- // MMailable::ReadNativeMailContent
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- Boolean MMailable::ReadNativeMailContent()
- {
- FailNonObject(fLetter);
- return fLetter->ReadNativeMailContent();
- }
-
- //----------------------------------------------------------------------------------------
- // MMailable::ReadStandardMailContent
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- Boolean MMailable::ReadStandardMailContent()
- {
- FailNonObject(fLetter);
- return fLetter->ReadStandardMailContent();
- }
-
- //----------------------------------------------------------------------------------------
- // MMailable::ReadStandardMailContent
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- Boolean MMailable::ReadSnapshotMailContent()
- {
- FailNonObject(fLetter);
- return fLetter->ReadSnapshotMailContent();
- }
-
-
- //----------------------------------------------------------------------------------------
- // MMailable::SetReplyContents
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void MMailable::SetReplyContents(TDocument* /*replyToDoc*/)
- {
- // Override to set up the reply document with contents
- // based on the original.
- }
-
- //========================================================================================
- // CLASS MMailing
- //========================================================================================
- #undef Inherited
-
- #pragma segment MAInit
- MA_DEFINE_CLASS_M0(MMailing);
-
- //----------------------------------------------------------------------------------------
- // MMailing constructor
- //----------------------------------------------------------------------------------------
- #pragma segment MAInit
-
- MMailing::MMailing()
- {
- gMailing = this;
- }
-
- //----------------------------------------------------------------------------------------
- // MMailing::GetAOCEIdentity
- // Note: may return an error if the identity can't be retrieved.
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- OSErr MMailing::GetAOCEIdentity(AuthIdentity& theIdentity,
- Boolean allowInteraction)
- {
- OSErr err;
- SDPIdentityKind idKind;
- AuthGetLocalIdentityPB pBlock;
-
- err = AuthGetLocalIdentity((AuthParamBlockPtr)&pBlock, FALSE);
-
- if (err == noErr)
- {
- theIdentity = pBlock.theLocalIdentity;
- }
- else if (allowInteraction)
- {
- FailOSErr(MAInteractWithUser());
-
- CStr255 localIDPrompt;
- GetIndString(localIDPrompt, kAOCEStrings, kGetIdentityPrompt);
- err = SDPPromptForID(&theIdentity, NULL, NULL, localIDPrompt, NULL,
- kSDPLocalIdentityMask, &idKind, NULL, 0);
- }
- return err;
- }
-
- //----------------------------------------------------------------------------------------
- // MMailing::DoMailerEvent
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- Boolean MMailing::DoMailerEvent(TToolboxEvent* event)
- {
- // Passes events to the standard mail package.
- // Returns TRUE if the SMP handled the event.
-
- Boolean result = FALSE;
- if (HasAOCEToolBox())
- {
- EventRecord theEvent;
- if (event)
- theEvent = event->fEventRecord;
- else
- {
- // call the same FrontWindowProc AOCE will call to get our front window
- WindowRef frontWindowRef = (WindowRef)CallFrontWindowProc(gFrontWindowUPP, 0);
- TWindow *frontWindow = TWindow::WMgrToWindow(frontWindowRef);
- if (frontWindow)
- frontWindow->Focus();
-
- BlockSet((Ptr) & theEvent, sizeof(EventRecord), 0);
- GetMouse((CPoint &)theEvent.where);
- LocalToGlobal((CPoint &)theEvent.where);
- theEvent.when = TickCount();
- theEvent.modifiers = 128;
- }
-
- // Don't handle mouse and key events, they are handled by the view.
- Boolean handleHere = (theEvent.what != mouseDown) && (theEvent.what != mouseUp) && (theEvent.what != keyDown) && (theEvent.what != autoKey);
- // However, give the mail package a crack at mouse downs that are not in our windows.
- // This is so it can drag stuff in from other apps.
- if (theEvent.what == mouseDown)
- {
- WindowPtr aWMgrWindow;
- short whereMouseDown = FindWindow(theEvent.where, &aWMgrWindow);
- handleHere = handleHere || (TWindow::WMgrToWindow(aWMgrWindow) == NULL);
- }
-
- if (handleHere)
- {
- OSErr err = 0;
- SMPMailerResult whatHappened = 0;
-
- err = SMPMailerEvent(&theEvent, &whatHappened, gFrontWindowUPP, (long)this);
- if ((whatHappened & kSMPCreateCopyWindowMask) || (whatHappened & kSMPDisposeCopyWindowMask))
- InvalidateMenuBar();
-
- result = (Boolean)(whatHappened & kSMPAppShouldIgnoreEventMask);
- }
- }
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // MMailing::DoOpenNextLetter
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void MMailing::DoOpenNextLetter(CommandNumber aCommandNumber)
- {
- FailOSErr(SMPInitMailer(0));
- AuthIdentity userIdentity;
-
- if (this->GetAOCEIdentity(userIdentity, TRUE) != noErr)
- return;
-
- FailInfo fi;
- Try(fi)
- {
- OSType theType = fMainLetterFileType;
- LetterDescriptor theLetter;
-
- FailOSErr(SMPGetNextLetter(&theType, 1, &theLetter));
-
- TOpenNextLetterCommand* anOpenNextLetterCommand = new TOpenNextLetterCommand;
- anOpenNextLetterCommand->IOpenNextLetterCommand(aCommandNumber);
- anOpenNextLetterCommand->fUseAppleEvent = TRUE;
- gDispatcher->PostCommand(anOpenNextLetterCommand);
-
- fi.Success();
- }
- else
- {
- if (fi.error == kSMPNoNextLetter)
- StdAlert(phNoNextLetter);
- else
- fi.ReSignal();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // MMailing::OpenOldLetters
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void MMailing::OpenOldLetters(CommandNumber itsOpenCommand,
- const CAEDesc& letterList)
- {
- // Opens letter documents from the PowerTalk mailbox.
- // Similar to OpenOld, but here we make the document, give it the letter descriptor,
- // then make the views. Then TDocument::OpenLetter gets called to read the letter
- // content.
-
- MAVolatileInit(TDocument*, aDocument, NULL);
- MAVolatileInit(TFile*, aFile, NULL);
-
- Size oldCodeReserve;
- Size oldMemReserve;
-
- GetReserveSize(oldCodeReserve, oldMemReserve);
-
- long numLetters = 0;
- FailOSErr(AECountItems(letterList, &numLetters));
- for (short index = 1; index <= numLetters; index++)
- {
- FailInfo fi;
- Try(fi)
- {
- {
- CTempDesc letterDesc;
- DescType ignoreKey;
- FailOSErr(AEGetNthDesc(letterList, index, typeLetterDesc, &ignoreKey, letterDesc));
-
- // Set reserve down a little to ensure that we can open existing documents
- SetReserveSize(oldCodeReserve, oldMemReserve / 2);
-
- Handle theLetterSpec = letterDesc.GetDataHandle();
-
- TDocument * otherDoc = this->FindLetter(theLetterSpec);
-
- if (otherDoc)
- {
- otherDoc->OpenAgain(itsOpenCommand, aDocument);
- SetReserveSize(oldCodeReserve, oldMemReserve);
- }
- else if (this->CanOpenLetter(itsOpenCommand, theLetterSpec))
- {
- FailNIL(aDocument = gApplication->DoMakeDocument(gApplication->KindOfDocument(itsOpenCommand, aFile), aFile));
-
- MMailable* mailDoc = MA_DYNAMIC_CAST(MMailable, aDocument);
- if (!mailDoc) Failure(minErr, 0);
- mailDoc->DoMakeLetter();
- TLetter* docLetter = mailDoc->fLetter;
- {
- // When opening a letter we first tell the letter which desc it should use, then it creates
- // its views, including the mailer. After creating the views we tell the letter to load its data.
-
- LetterDescriptor theDescriptor;
- theDescriptor.onDisk = FALSE;
- theDescriptor.u.mailboxSpec = **(LetterSpec * *)theLetterSpec;
- Handle theDescHdl = NewPermHandle(sizeof(theDescriptor));
- **(LetterDescriptor * *)theDescHdl = theDescriptor;
-
- docLetter->SetLetterDesc(theDescHdl);
-
- aDocument->DoMakeViews(kForDisplay);
- docLetter->OpenLetter();
- }
-
- FailSpaceIsLow(); // Fail if the document leaves us with no
- // memory
- // Set the reserve back to where it was
- SetReserveSize(oldCodeReserve, oldMemReserve);
-
- // Don't attempt to show the windows until we're sure we won't fail
- aDocument->DoPostMakeViews(kForDisplay);
- }
- else
- Failure(errNotMyType, 0);
- }
- fi.Success();
- }
- else // Recover
- {
- if (aDocument != NULL)
- aDocument = (TDocument *)FreeIfObject(aDocument); // The document will free the file
- else
- aFile = (TFile *)FreeIfObject(aFile); // otherwise its our responsibility
-
- // Set the reserve back to where it was
- SetReserveSize(oldCodeReserve, oldMemReserve);
-
- FailNewMessage(fi.error, fi.message, messageOpenFailed);
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // MMailing::FindLetter
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- TDocument* MMailing::FindLetter(Handle itsSpec)
- {
- CDocumentIterator iter(gDispatcher);
- MMailable* mailDoc = NULL;
-
- for (TDocument * aDocument = iter.FirstDocument(); iter.More(); aDocument = iter.NextDocument())
- {
- mailDoc = MA_DYNAMIC_CAST(MMailable, aDocument);
- if ((mailDoc) && mailDoc->FindLetter(itsSpec))
- return aDocument;
- }
- return NULL; // No document already open
- }
-
- //----------------------------------------------------------------------------------------
- // MMailing::CanOpenLetter
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- Boolean MMailing::CanOpenLetter(CommandNumber /* itsCommandNumber */,
- Handle /* itsSpec */)
- {
- return true;
- }
-
- //----------------------------------------------------------------------------------------
- // MMailing::IsLetterFileType
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- Boolean MMailing::IsLetterFileType(OSType theFileType)
- // Return true if theFileType is a letter format this application can open.
- {
- return (theFileType == fMainLetterFileType);
- }
-
- //----------------------------------------------------------------------------------------
- // MMailing::TextToDSSpecGlue
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- pascal OSErr MMailing::TextToDSSpecGlue(DescType /*typeCode*/, const void *dataPtr, Size dataSize, DescType /*toType*/, long /*handlerRefcon*/, AEDesc *result)
- {
- CAEDesc localDesc;
- OSErr theErr = gMailing->TextToDSSpec(dataPtr, dataSize, localDesc);
- *result = (AEDesc &)localDesc;
- return theErr;
- }
-
- //----------------------------------------------------------------------------------------
- // MMailing::DSSpecToTextGlue
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- pascal OSErr MMailing::DSSpecToTextGlue(DescType /*typeCode*/, const void *dataPtr, Size dataSize, DescType /*toType*/, long /*handlerRefcon*/, AEDesc *result)
- {
- CAEDesc localDesc;
- OSErr theErr = gMailing->DSSpecToText(dataPtr, dataSize, localDesc);
- *result = (AEDesc &)localDesc;
- return theErr;
- }
-
- //----------------------------------------------------------------------------------------
- // MMailing::TextToDSSpec
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- OSErr MMailing::TextToDSSpec(const void *textPtr, Size textSize, CAEDesc &result)
- {
- OSErr resultErr = noErr;
- FailInfo fi;
- Try(fi)
- {
- CDSSpec theSpec;
- CStr255 str;
- str.Length() = (unsigned char)Min(textSize, kStr255Len);
- MABlockMove(textPtr, &str.fStr[1], str.Length());
- theSpec.StringToAddress(str);
- theSpec.GetAEDesc(result);
- fi.Success();
- }
- else
- {
- resultErr = errAECoercionFail;
- }
- return resultErr;
- }
-
- //----------------------------------------------------------------------------------------
- // MMailing::DSSpecToText
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- OSErr MMailing::DSSpecToText(const void *dataPtr, Size /*dataSize*/, CAEDesc &result)
- {
- OSErr resultErr = noErr;
- FailInfo fi;
- Try(fi)
- {
- CDSSpec theSpec((PackedDSSpecPtr)dataPtr);
- CStr255 str;
- theSpec.AddressToString(str);
- result.PutString(str);
- fi.Success();
- }
- else
- {
- resultErr = errAECoercionFail;
- }
- return resultErr;
- }
-
-
- //========================================================================================
- // Class TOpenNextLeterCommand
- //========================================================================================
- #undef Inherited
- #define Inherited TCommand
-
- #pragma segment ConstructorRes
- MA_DEFINE_CLASS_M1(TOpenNextLetterCommand, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TOpenNextLetterCommand::TOpenNextLetterCommand
- //----------------------------------------------------------------------------------------
- TOpenNextLetterCommand::TOpenNextLetterCommand()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TOpenNextLetterCommand::~TOpenNextLetterCommand
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
- TOpenNextLetterCommand::~TOpenNextLetterCommand()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TOpenNextLetterCommand::IOpenNextLetterCommand
- //----------------------------------------------------------------------------------------
- void TOpenNextLetterCommand::IOpenNextLetterCommand(CommandNumber itsCommandNumber)
- {
- this->ICommand(itsCommandNumber, gDispatcher, kCantUndo, kDoesNotCauseChange, NULL);
- }
-
- //----------------------------------------------------------------------------------------
- // TOpenNextLetterCommand::DoIt
- //----------------------------------------------------------------------------------------
- void TOpenNextLetterCommand::DoIt()
- {
- if (HasAOCEToolBox() && gMailing)
- {
- LetterDescriptor theLetter;
- CTempDesc theList;
- OSType theType = gMailing->fMainLetterFileType;
-
- FailOSErr(MAInteractWithUser());
- FailOSErr(SMPGetNextLetter(&theType, 1, &theLetter));
- theList.CreateList();
- {
- CTempDesc theLetterDesc;
- FailOSErr(AECreateDesc(typeLetterDesc, (Ptr)&theLetter.u.mailboxSpec,
- sizeof(LetterSpec), theLetterDesc));
- theList.PutListItem(0, theLetterDesc);
- }
- gMailing->OpenOldLetters(this->fIdentifier, theList);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TOpenNextLetterCommand::MakeAppleEvent
- //----------------------------------------------------------------------------------------
- #pragma segment MACommandRes
-
- TAppleEvent* TOpenNextLetterCommand::MakeAppleEvent()
- {
- TAppleEvent* theOpenNextLetterEvent = NULL;
-
- theOpenNextLetterEvent = new TAppleEvent;
- theOpenNextLetterEvent->IAppleEvent(kAEMailSuite, kAEOpenNextLetter, gServerAddress, kAEWaitReply);
-
- return theOpenNextLetterEvent;
- }
-
-
- #endif // qPowerTalk
-
- //----------------------------------------------------------------------------------------
- // End of UMailable.cp
-
- #pragma segment Inline
-